﻿Public Class RenameDatacutForm

    Private Sub SaveButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SaveButton.Click

        UpdateDescription()

    End Sub

    Private Sub UpdateDescription()

        Dim sql, TheDataCut, TheTable, NewDescription As String

        Dim TheSelectedNode As New TreeNode

        TheSelectedNode = DatacutsForm.TreeView.SelectedNode

        TheDataCut = Trim(DatacutsForm.TreeView.SelectedNode.Name.ToString)
        TheTable = Trim(DatacutsForm.TreeView.SelectedNode.Parent.Name.ToString)
        NewDescription = Trim(DescriptionBox.Text)

        If NewDescription.Length = 0 Then
            MessageBox.Show("You cannot save a blank description", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Exit Sub
        End If

        sql = "Update " & TheTable & " set Description = '" & NewDescription & "' where DataCut_ID = '" & TheDataCut & "' "

        RunNonQuery(sql)

        MessageBox.Show("Description has been successfully updated", "Description Updated", MessageBoxButtons.OK, MessageBoxIcon.Information)

        Me.Visible = False

        TheSelectedNode.Text = NewDescription


    End Sub

    Private Sub RenameDatacutForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub
End Class